package com.see.services.impl;

import java.util.Collection;

import com.google.inject.Inject;
import com.see.domain.model.StockDetail;
import com.see.network.api.StockDetailParser;
import com.see.services.api.StockDynamicDataFetcher;

public class StockDynamicDataFetcherImpl implements StockDynamicDataFetcher {

    private StockDetailParser googleFinaceData;
    private final String      GOOGLE_BASE_URL = "https://finance.google.com/finance/info?client=ig&q=";

    @Inject
    public StockDynamicDataFetcherImpl(StockDetailParser stockDetailParser) {
        this.googleFinaceData = stockDetailParser;
    }

    public StockDetail getStockDetailBySymbol(String inputSymbol) {
        String requestURL = GOOGLE_BASE_URL + inputSymbol;
        Collection<StockDetail> stockDetailCollection = googleFinaceData.parse(requestURL);
        // Only one record will be returned.
        StockDetail stockDetail = stockDetailCollection.toArray(new StockDetail[stockDetailCollection.size()])[0];

        return stockDetail;
    }

    /*
        public List<StockDetail> getStockDetailsBySector(String sector) {
            String symbolList = "";
            String requestURL = "";
            StaticData[] stockDataList = dataNucleusUtil.findBySector(sector);
            for (StaticData staticData : stockDataList) {
                symbolList += staticData.getSymbol() + ",";

            }
            requestURL = GOOGLE_BASE_URL + symbolList;
            Collection<StockDetail> stockDetailCollection = googleFinaceData.parse(requestURL);
            List<StockDetail> stockDetailList = (List) stockDetailCollection;

            return stockDetailList;
        }*/

    /* public List<StockDetail> getStockDetailsByIndustry(String industry) {
         String symbolList = "";
         String requestURL = "";
         StaticData[] stockDataList = dataNucleusUtil.findByIndustry(industry);
         for (StaticData staticData : stockDataList) {
             symbolList += staticData.getSymbol() + ",";

         }
         requestURL = GOOGLE_BASE_URL + symbolList;
         Collection<StockDetail> stockDetailCollection = googleFinaceData.parse(requestURL);
         List<StockDetail> stockDetailList = (List) stockDetailCollection;

         return stockDetailList;
     }*/

}
